﻿//编写并测试一个函数FIbonacci()，在该函数中使用循环代替递归完成斐波纳契数列的计算。
#include <stdio.h>
unsigned long Fibonacci(unsigned n);
int main(void){	
	unsigned n;	printf("enter a interger:\n");
	while (scanf("%u",&n) == 1)	{       
		printf("the Fibonacci is:%u\n",Fibonacci(n)); 
		printf("enter the next interger:\n");	
	}  
	return 0;
}
unsigned long Fibonacci(unsigned n){
	int ans1 = 1;
	int ans2 = 1;
	int i;   
	if (n <= 2) {      
		return 1;    
	}
    else     
for (i = 0;i < n - 2 ;i++ ){             
	ans1 = ans1 + ans2;     
	ans2 = ans1 - ans2;     
}   
return ans1;	
}
